<?php

/**
 * Libro filter form.
 *
 * @package    filters
 * @subpackage Libro *
 * @version    SVN: $Id: sfDoctrineFormFilterTemplate.php 11675 2008-09-19 15:21:38Z fabien $
 */
class LibroFormFilter extends BaseLibroFormFilter
{
  public function configure()
  {
        $this->widgetSchema['titulo']->addOption('with_empty', false);
        $this->widgetSchema['coleccion_libro_id']->addOption('order_by', array('nombre','asc'));
        $this->widgetSchema['editor_id']->addOption('order_by', array('nombre','asc'));
        $this->widgetSchema['deudor_id']->addOption('order_by', array('nombre','asc'));
        $this->widgetSchema['lugar_id']->addOption('order_by', array('nombre','asc'));
        $this->widgetSchema['escritores_list']->addOption('order_by', array('apellidos','asc'));
        $this->widgetSchema['generos_list']->addOption('order_by', array('nombre','asc'));
  }

  public function addGenerosListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }
    sfContext::getInstance()->getLogger()->info(($query->getSqlQuery()));
    $query->groupBy('id')->leftJoin('r.TrataLibro TrataLibro')
          ->andWhereIn('TrataLibro.genero_id', $values)
          ->having('COUNT(TrataLibro.genero_id) = '.count($values));
  }

}